/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gov.mtc.dgac.licencias.persistence;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import pe.gov.mtc.dgac.licencias.bean.ClienteTO;
import pe.gov.mtc.dgac.licencias.exception.TransactionException;
import pe.gov.mtc.dgac.licencias.util.Page;

/**
 *
 * @author externo.gamaro
 */
public class ClienteImplDAO extends SqlMapClientTemplate implements ClienteDAO {
     Log logger = LogFactory.getLog(this.getClass());

    public List<ClienteTO> buscarCliente(ClienteTO cliente) throws TransactionException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Page buscarCliente(ClienteTO cliente, int page, int pageSize) throws TransactionException {
         
          List<ClienteTO> list=null;
          int first = Page.getStartItemByPage(page, pageSize);
          int last = first + pageSize - 1;
          int totalElements=0;
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodCli",cliente.getCodCliente()); 
          parmMap.put("pNombres",cliente.getNombres()); 
          parmMap.put("pApePat",cliente.getApellidoPat()); 
          parmMap.put("pApeMat",cliente.getApellidoMat()); 
          parmMap.put("pNumDoc",cliente.getNumIdDoc()); 
          parmMap.put("pFistElement",first); 
          parmMap.put("pLastElement",last); 
          
          queryForObject("Cliente.buscarCliente", parmMap);
          list=(List<ClienteTO>)parmMap.get("pResult");
          String totReg=(String) parmMap.get("pTotReg");
          totalElements=Integer.parseInt(totReg);
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return new Page(list,page,pageSize,totalElements);
    }

}
